

/*
 * @(#)MaintNextStepDueDatesAction.java
 *
 * Copyright (c) 2003 DCIVision Ltd
 * All rights reserved.
 *
 * This software is the confidential and proprietary information of DCIVision
 * Ltd ("Confidential Information").  You shall not disclose such Confidential
 * Information and shall use it only in accordance with the terms of the license
 * agreement you entered into with DCIVision Ltd.
 */
package com.dcivision.workflow.web;

import java.util.ArrayList;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import com.dcivision.framework.SystemFunctionConstant;
import com.dcivision.framework.Utility;
import com.dcivision.framework.web.AbstractMaintAction;
import com.dcivision.workflow.bean.MtmWorkflowStepWorkflowStep;
import com.dcivision.workflow.bean.WorkflowStep;
import com.dcivision.workflow.dao.MtmWorkflowStepWorkflowStepDAObject;
import com.dcivision.workflow.dao.WorkflowStepDAObject;

/**
  MaintNextStepDueDatesAction.java

  This class is for set the next steps due dates.

    @author          Tony Chen
    @company         DCIVision Limited
    @creation date   22/09/2004
    @version         $Revision: 1.4 $
*/
public class MaintNextStepDueDatesAction extends AbstractMaintAction {

  public static final String REVISION = "$Revision: 1.4 $";

  /** Creates a new instance of MaintWorkflowProgressAction */
  public MaintNextStepDueDatesAction() {
    super();
  }

  /** getFunctionCode
   *
   * Abstract function which sub-class should implement to return the corresponding
   * function code.
   *
   * @return   The function code
   */
  public String getFunctionCode() {
    return(SystemFunctionConstant.WORKFLOW_RECORD);
  }

  /** getMajorDAOClassName
   *
   * Abstract function which sub-class should implement to return the corresponding
   * major DAO class name used in this class.
   *
   * @return   The DAO class name
   */
  public String getMajorDAOClassName() {
    return("com.dcivision.workflow.dao.WorkflowRecordDAObject");
  }

  public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws ServletException {
    
    String wfRecordID = request.getParameter("workflowRecordID");
    String currentStepID = request.getParameter("currentStepID");
    
    WorkflowStepDAObject stepDAO = new WorkflowStepDAObject(this.getSessionContainer(request),this.getConnection(request));
    MtmWorkflowStepWorkflowStepDAObject stepStepDAO = new MtmWorkflowStepWorkflowStepDAObject(this.getSessionContainer(request),this.getConnection(request));
    
    List mtmStepList = new ArrayList();
    if (!Utility.isEmpty(currentStepID)){
        mtmStepList = stepStepDAO.getListByParentStepID(new Integer(currentStepID));  
    } else {
      WorkflowStep wfStep = (WorkflowStep)stepDAO.getSubmitStepByWorkflowRecordID(new Integer(wfRecordID));
      mtmStepList = stepStepDAO.getListByParentStepID(wfStep.getID());
    }   
    
    List wfStepList = new ArrayList();
    
    for(int j=0; j<mtmStepList.size(); j++){
      MtmWorkflowStepWorkflowStep stepStep = (MtmWorkflowStepWorkflowStep)mtmStepList.get(j);
      WorkflowStep tmpWfStep = (WorkflowStep)stepDAO.getObjectByID(stepStep.getChildStepID());
      if(WorkflowStep.DYNAMIC_ASSIGN_DUE_DATE_TRUE.equals(tmpWfStep.getAllowAssignDueDate()) ||
         WorkflowStep.DYNAMIC_ASSIGN_DUE_DATE_MANDATORY.equals(tmpWfStep.getAllowAssignDueDate()) ){
        wfStepList.add(tmpWfStep);
      }
    }
    
    request.setAttribute("workflowStepList",wfStepList);
    return super.execute(mapping,form,request,response);
  }
  
}
